﻿CREATE FUNCTION dbo.Top10PercentIndexes
	(@DatabaseID AS int)  RETURNS TABLE AS

RETURN

  SELECT  TOP (10)  dt.TableName,
					ifd.IndexName,
					ifd.IndexType,
					CONVERT(DECIMAL(16, 1),ifd.IndexSize) AS IndexSize,
					ifd.Statistics_LastUpdatedDate,			
					ifd.Fragmentation
					
FROM         [Index] AS ifd INNER JOIN
             [Table] AS dt ON dt.TableID = ifd.TableID                      
                      
WHERE     @DatabaseID = dt.DatabaseID
                      
ORDER BY IndexSize desc     
	

